package com.xx.news.viewmodel;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.xx.news.base.BaseViewModel;
import com.xx.news.entity.Jingxuan;
import com.xx.news.entity.Qiche;
import com.xx.news.repository.NewsRepository;
import com.xx.news.repository.NewsRepository1;

import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class QicheModel extends BaseViewModel {
    NewsRepository repository;
    private MutableLiveData<Qiche> qiches = new MutableLiveData<>();

    public QicheModel(@NonNull Application application) {
        super(application);
        setTitle("汽车");
        repository = new NewsRepository(application);
    }

    public LiveData<Qiche> getLiveData() {
        return qiches;
    }


    public void getDate() {
        getUC().getShowDialogEvent().call();
        repository.getQiche().subscribe(new Observer<Qiche>() {
            @Override
            public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
                Log.d("abcd", "onSubscribe");
            }

            @Override
            public void onNext(@io.reactivex.rxjava3.annotations.NonNull Qiche qiche) {
                Log.d("abcd", "onNext: " + qiche.toString());
                getUC().getDismissDialogEvent().call();
                qiches.postValue(qiche);
            }

            @Override
            public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
                Log.d("abcd", "onError");
            }

            @Override
            public void onComplete() {
                Log.d("abcd", "onComplete");
            }
        });
    }

}
